package com.david.system.service.impl;

import com.david.system.mapper.VendorMapper;
import com.david.system.pojo.Entity.VendorEntity;
import com.david.system.pojo.VO.VendorVO;
import com.david.system.service.VendorService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VendorServiceImpl implements VendorService {
    @Autowired
    private VendorMapper vendorMapper;

    @Override
    public List<VendorVO> getVendorList() {
        return vendorMapper.selectVendorAll();
    }

    @Override
    public void editVendor(VendorVO vendorVO) {
        Integer statusId = vendorMapper.selectVendorStatusIdByStatus(vendorVO.getStatus());
        VendorEntity vendorEntity = new VendorEntity();
        BeanUtils.copyProperties(vendorVO,vendorEntity);
        vendorEntity.setStatusId(statusId);
        vendorMapper.updateVendor(vendorEntity);
    }

    @Override
    public void delVendor(Integer id) {
        vendorMapper.deleteVendorById(id);
    }

    @Override
    public void addVendor(VendorVO vendorVO) {
        Integer statusId = vendorMapper.selectVendorStatusIdByStatus(vendorVO.getStatus());
        VendorEntity vendorEntity = new VendorEntity();
        BeanUtils.copyProperties(vendorVO,vendorEntity);
        vendorEntity.setStatusId(statusId);
        vendorMapper.insertVendor(vendorEntity);
    }
}
